﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Google.Translates.WebService.Rules
{
    /// <summary>
    /// 這一個是3種Translate方法調用過程,對業務邏輯進行驗證的基類, 實現一些共用而又簡單的邏輯驗證方法
    /// 方法[TranslateByTextTramsmission] 對應用的 Rule Class is [TextTransmissionRule]
    /// 方法[TranslateByFileTransmission] 對應用的 Rule Class is [FileTransmissionRule]
    /// 方法[TranslateByDbUpdate] 對應用的 Rule Class is [DbUpdateRule]
    /// </summary>
    public abstract class BaseRule
    {
        private const string ERROR_MSG_FAIL = "Translation is fail";
        private const string ERROR_MSG_NOT_SUPPORT_LANGUAGE = "Not support the language";
        private const string ERROR_MSG_TARGET_LANGUAGE_IS_NULL = "Target-language is empty. Not Allowed!";

        protected string CheckTheLanguageCodeIsUseful(string sourceLanguageCode, string targetLanguageCode)
        {
            var errMsg = "";
            if (!string.IsNullOrEmpty(sourceLanguageCode) && !LanguageHelper.CheckLanguageIsSupport(sourceLanguageCode))
                errMsg += ERROR_MSG_NOT_SUPPORT_LANGUAGE + " which the source-language's key is " + sourceLanguageCode + ".\r\n";
            if (string.IsNullOrEmpty(targetLanguageCode))
                errMsg += ERROR_MSG_TARGET_LANGUAGE_IS_NULL + "\r\n";
            else if (!LanguageHelper.CheckLanguageIsSupport(targetLanguageCode))
                errMsg += ERROR_MSG_NOT_SUPPORT_LANGUAGE + " which the target-language's  key is " + targetLanguageCode + ".\r\n";
            return errMsg;
        }
    }
}
